实现一个将接收到的 String 参数转换为一个字母 Union 的类型
例如:
type Test = '123';
type Result = StringToUnion<Test>; // expected to be "1" | "2" | "3"
// 答案 1
type StringToUnion<T extends string> = T extends `${infer L}${infer R}`
? L | StringToUnion<R>
: never
// 答案 2
type StringToUnion<T extends string, U extends string[] = []> = T extends `${infer L}${infer R}`
? StringToUnion<R, [L, ...U]>
: U[number]